/*
 * utils/setters.hh - Macros for compact setters declarations.
 * Copyright (C) 2007  Mikhail Vorozhtsov
 * See the LICENSE section of the README file for details.
 */

/* $Id$ */

#ifndef HEADER_UTILS_SETTERS_HH
#define HEADER_UTILS_SETTERS_HH

#define UTILS_RAW_CTOR(CONTAINER,TYPE,FIELD) \
  INLINE \
  CONTAINER (TYPE x) : FIELD (x) \
  { \
  }

#define UTILS_RAW_CTOR_WITH_DEFAULT(CONTAINTER,TYPE,FIELD,DEFAULT) \
  INLINE \
  CONTAINTER (TYPE x = DEFAULT) : FIELD (x) \
  { \
  }

#define UTILS_RAW_CAST(CONTAINER,TYPE,FIELD) \
  INLINE \
  operator TYPE () \
  { \
    return FIELD; \
  }

#define UTILS_RAW_ASSIGN(CONTAINER,TYPE,FIELD) \
  INLINE \
  CONTAINER & \
  operator= (TYPE x) \
  { \
    this->FIELD = x; \
    return *this; \
  }

#define UTILS_NAMED_RAW(CONTAINER,TYPE,FIELD) \
  UTILS_RAW_CTOR (CONTAINER, TYPE, FIELD) \
  UTILS_RAW_CAST (CONTAINER, TYPE, FIELD) \
  UTILS_RAW_ASSIGN (CONTAINER, TYPE, FIELD) \
  UTILS_SETTER (CONTAINER, TYPE, FIELD)

#define UTILS_NAMED_RAW_WITH_DEFAULT(CONTAINER,TYPE,FIELD,DEFAULT) \
  UTILS_RAW_CTOR_WITH_DEFAULT (CONTAINER, TYPE, FIELD, DEFAULT) \
  UTILS_RAW_CAST (CONTAINER, TYPE, FIELD) \
  UTILS_RAW_ASSIGN (CONTAINER, TYPE, FIELD) \
  UTILS_SETTER (CONTAINER, TYPE, FIELD)

#define UTILS_RAW_ZERO(CONTAINER,TYPE) \
  UTILS_NAMED_RAW_WITH_DEFAULT (CONTAINER, TYPE, raw, 0)

#define UTILS_NAMED_SETTER(CONTAINER,TYPE,FIELD,NAME) \
  INLINE \
  CONTAINER & \
  set_ ## NAME (TYPE x) \
  { \
    this->FIELD = x; \
    return *this; \
  }

#define UTILS_NAMED_SETTER_WITH_DEFAULT(CONTAINER,TYPE,FIELD,NAME,DEFAULT) \
  INLINE \
  CONTAINER & \
  set_ ## NAME (TYPE x = DEFAULT) \
  { \
    this->FIELD = x; \
    return *this; \
  }

#define UTILS_SETTER(CONTAINER,TYPE,FIELD) \
  UTILS_NAMED_SETTER (CONTAINER, TYPE, FIELD, FIELD)

#define UTILS_SETTER_WITH_DEFAULT(CONTAINER,TYPE,FIELD,DEFAULT) \
  UTILS_NAMED_SETTER_WITH_DEFAULT (CONTAINER, TYPE, FIELD, FIELD, DEFAULT)

#define UTILS_BOOL_SETTER(CONTAINER,FIELD) \
  UTILS_SETTER_WITH_DEFAULT (CONTAINER, bool, FIELD, true)

#endif /* HEADER_UTILS_SETTERS_HH */

